﻿#include <iostream>
#include <vector>
#include <string>
using namespace std;

class Solution
{
public:
    // 738. 单调递增的数字
    int monotoneIncreasingDigits(int n)
    {
        string s(to_string(n));
        int i = 0, m = s.size();
        while (i + 1 < m && s[i] <= s[i + 1])
            ++i;
        if (i + 1 == m)
            return n;
        while (i - 1 >= 0 && s[i] == s[i - 1])
            --i;
        s[i]--;
        for (int j = i + 1; j < m; ++j)
            s[j] = '9';
        return stoi(s);
    }

    // 991. 坏了的计算器
    int brokenCalc(int startValue, int target)
    {
        int ret = 0;
        while (target > startValue)
        {
            if (target % 2 == 0)
                target /= 2;
            else
                target += 1;
            ret++;
        }
        return ret + startValue - target;
    }
};

int main()
{
    // cout << Solution().monotoneIncreasingDigits(984645632) << endl;

    cout << Solution().brokenCalc(86, 94564) << endl;

    return 0;
}